class Solution(object):
    def searchMatrix(self,matrix, target):
        if not matrix: return False
        row, col = 0, len(matrix[0]) - 1  # 初始化右上角
        while row < len(matrix) and col >= 0:
            if matrix[row][col] == target:
                return True
            elif matrix[row][col] > target:
                col -= 1  # 排除当前列
            else:
                row += 1  # 排除当前行
        return False


a= [[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20],[21,22,23,24,25]]
print(Solution().searchMatrix(a, 19))
